<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GitCode 問題反饋插件調試</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 20px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
        }
        .container {
            max-width: 900px;
            margin: 0 auto;
            background: white;
            padding: 40px;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        }
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
            font-size: 2.5em;
        }
        .debug-section {
            margin: 20px 0;
            padding: 20px;
            border: 2px solid #e0e0e0;
            border-radius: 10px;
            background: #f9f9f9;
        }
        .debug-section h2 {
            color: #ff6b6b;
            margin-top: 0;
        }
        .debug-button {
            background: linear-gradient(45deg, #ff6b6b, #ee5a24);
            color: white;
            border: none;
            padding: 15px 30px;
            border-radius: 25px;
            cursor: pointer;
            font-size: 16px;
            font-weight: bold;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
            margin: 10px;
        }
        .debug-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
        }
        .result {
            margin-top: 15px;
            padding: 15px;
            border-radius: 8px;
            font-family: 'Courier New', monospace;
            white-space: pre-wrap;
        }
        .success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        .info {
            background: #d1ecf1;
            color: #0c5460;
            border: 1px solid #bee5eb;
        }
        .code-block {
            background: #2d3748;
            color: #e2e8f0;
            padding: 20px;
            border-radius: 8px;
            margin: 15px 0;
            overflow-x: auto;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🔧 GitCode 問題反饋插件調試</h1>
        
        <div class="debug-section">
            <h2>📋 調試信息</h2>
            <div id="debugInfo" class="result info">正在加載...</div>
        </div>

        <div class="debug-section">
            <h2>🧪 調試測試</h2>
            <button class="debug-button" onclick="testScriptLoad()">測試腳本加載</button>
            <button class="debug-button" onclick="testButtonCreation()">測試按鈕創建</button>
            <button class="debug-button" onclick="testManualButton()">手動創建按鈕</button>
            <div id="testResult" class="result" style="display: none;"></div>
        </div>

        <div class="debug-section">
            <h2>📝 測試內容</h2>
            <p>請選擇下面的文本來測試文本選擇功能：</p>
            <div class="code-block">
// 這是一段示例代碼
function testFunction() {
    console.log("Hello, GitCode!");
    return "測試成功";
}

// 選擇這段文本，然後點擊"測試文本選擇"按鈕
const result = testFunction();
            </div>
        </div>
    </div>

    <script>
        // 調試信息
        function updateDebugInfo() {
            const debugDiv = document.getElementById('debugInfo');
            const info = [
                `window.require: ${typeof window.require}`,
                `BugReporter: ${typeof BugReporter}`,
                `document.readyState: ${document.readyState}`,
                `已加載腳本數量: ${document.scripts.length}`,
                `按鈕數量: ${document.querySelectorAll('.gitbook-plugin-gitcode-issue-feedback').length}`
            ].join('\n');
            debugDiv.textContent = info;
        }

        function showResult(message, type = 'info') {
            const resultDiv = document.getElementById('testResult');
            resultDiv.textContent = message;
            resultDiv.className = `result ${type}`;
            resultDiv.style.display = 'block';
        }

        function testScriptLoad() {
            try {
                updateDebugInfo();
                showResult('✅ 調試信息已更新', 'success');
            } catch (error) {
                showResult(`❌ 調試錯誤：\n${error.message}`, 'error');
            }
        }

        function testButtonCreation() {
            try {
                const button = document.querySelector('.gitbook-plugin-gitcode-issue-feedback');
                if (button) {
                    showResult('✅ 按鈕已存在！\n按鈕文本: ' + button.textContent, 'success');
                } else {
                    showResult('❌ 按鈕不存在！\n等待插件初始化...', 'error');
                }
            } catch (error) {
                showResult(`❌ 按鈕測試錯誤：\n${error.message}`, 'error');
            }
        }

        function testManualButton() {
            try {
                // 手動創建按鈕
                const button = document.createElement('button');
                button.textContent = '手動測試按鈕';
                button.className = 'gitbook-plugin-gitcode-issue-feedback';
                button.style.cssText = `
                    position: fixed;
                    right: 20px;
                    bottom: 20px;
                    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                    color: white;
                    border: none;
                    border-radius: 25px;
                    padding: 12px 20px;
                    font-size: 14px;
                    font-weight: 600;
                    cursor: pointer;
                    z-index: 1000;
                `;
                
                button.addEventListener('click', function() {
                    alert('手動按鈕點擊成功！');
                });
                
                document.body.appendChild(button);
                showResult('✅ 手動按鈕創建成功！', 'success');
            } catch (error) {
                showResult(`❌ 手動按鈕創建錯誤：\n${error.message}`, 'error');
            }
        }

        // 頁面加載完成後
        document.addEventListener('DOMContentLoaded', function() {
            console.log('🚀 調試頁面已加載');
            updateDebugInfo();
        });

        // 監聽腳本加載
        window.addEventListener('load', function() {
            console.log('📄 頁面完全加載');
            updateDebugInfo();
        });
    </script>

    <!-- 加載插件 -->
    <script src="plugin.js" onload="console.log('✅ 插件腳本加載完成')" onerror="console.error('❌ 插件腳本加載失敗')"></script>
</body>
</html>
